//
//  pch.swift
//
//  Copyright © 2017年. All rights reserved.
//

import UIKit

// 判断系统
let IOS7 = Int(UIDevice.current.systemVersion)! >= 7 ? true : false;
let IOS8 = Int(UIDevice.current.systemVersion)! >= 8 ? true : false;
let IOS9 = Int(UIDevice.current.systemVersion)! >= 9 ? true : false;
let IOS11 = Int(UIDevice.current.systemVersion)! >= 11 ? true : false;

// 判断设备
func isX() -> Bool {
    if UIScreen.main.bounds.height >= 812 {
        return true
    }
    return false
}

//自适应
func _sizeofString(_ string: String?, font: UIFont?, maxSize: CGSize) -> CGSize {
      return string?.boundingRect(with: maxSize, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedStringKey.font: font as Any], context: nil).size ?? CGSize.zero
  }

let LLSCREENW = UIScreen.main.bounds.width
let LLSCREENH = UIScreen.main.bounds.height

//MARK:NAV高度
let NavBarHight: CGFloat = topPadding() + 44
//MARK:TABBAR高度
let TabbarHeight: CGFloat = bottomPadding() + 49
//底部安全区域
let IphoneXMarginBottom:CGFloat = isX() ? bottomPadding() : 0.01
//顶部安钱区域
let IphoneTopArea: CGFloat = topPadding()

let LLTHEMECOLOR = UIColor.yellow

///底部的安全间隙是31 而不是34
func bottomPadding() -> CGFloat{
    var bottomHeight: CGFloat = 0
    if #available(iOS 13.0, *) {
        let statusBarManager = UIApplication.shared.windows.first?.safeAreaInsets
        bottomHeight = statusBarManager?.bottom ?? 0
    }else{
        if #available(iOS 11.0, *) {
            bottomHeight = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
        } else {
            bottomHeight = 0
        }
    }
    return bottomHeight
}

///底部的安全间隙是31 而不是34
private func topPadding() -> CGFloat{
    var topHeight: CGFloat = 0
    if #available(iOS 13.0, *) {
        let statusBarManager = UIApplication.shared.windows.first?.safeAreaInsets
        topHeight = statusBarManager?.top ?? 0
    }else{
        if #available(iOS 11.0, *) {
            topHeight = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0
        } else {
            topHeight = 0
        }
    }
    return topHeight
}

///本地化
func MMLocalizedString(_ title: String, comment: String) -> String {
   return LocalizableUitl.setLaunguageText(key: title)
}

func LLRandomColor() -> UIColor{
    let r = CGFloat(arc4random()%256)
    let g = CGFloat(arc4random()%256)
    let b = CGFloat(arc4random()%256)
    return UIColor(red: r/255, green: g/255, blue: b/255, alpha: 1)
}

func RGBCOLOR(r:CGFloat,_ g:CGFloat,_ b:CGFloat) -> UIColor{
    return UIColor(red: (r)/255.0, green: (g)/255.0, blue: (b)/255.0, alpha: 1.0)
}

let LLBigFontSize: CGFloat = 18
let LLNomalFontSize:CGFloat = 14
let LLSmallFontSize:CGFloat = 10

// 自定义打印方法
func printLog<T>(_ message : T, file : String = #file, funcName : String = #function, lineNum : Int = #line) {
    
    #if DEBUG
        
        let fileName = (file as NSString).lastPathComponent
        
        print("\(fileName):(\(lineNum))-\(message)")
        
    #endif
}


